package com.design.working.service.impl;

import com.design.working.dao.impl.LoginDAOImpl;
import com.design.working.dto.LoginDTO;
import com.design.working.entity.Admin;
import com.design.working.entity.Counselor;
import com.design.working.entity.DeptEmployee;
import com.design.working.entity.Student;
import com.design.working.service.LoginService;
import com.design.working.vo.ResponseVO;

import java.sql.SQLException;

/**
 * 登录服务层
 * @author gavin
 * @date 2022/5/7 20:58
 */
public class LoginServiceImpl implements LoginService {

    private final LoginDAOImpl loginDAOImpl = new LoginDAOImpl();

    @Override
    public ResponseVO<Student> studentLogin(LoginDTO loginDTO) {
        Student student = null;
        try {
            student = loginDAOImpl.studentLogin(loginDTO);
            if (student == null) {
                return ResponseVO.error("用户名或密码错误");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ResponseVO.success(student);
    }

    @Override
    public ResponseVO<Counselor> counselorLogin(LoginDTO loginDTO) {
        Counselor counselor = null;
        try {
            counselor = loginDAOImpl.counselorLogin(loginDTO);
            if (counselor == null) {
                return ResponseVO.error("用户名或密码错误");

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ResponseVO.success(counselor);
    }

    @Override
    public ResponseVO<DeptEmployee> deptEmployeeLogin(LoginDTO loginDTO) {
        DeptEmployee deptEmployee = null;
        try {
            deptEmployee = loginDAOImpl.deptEmployeeLogin(loginDTO);
            if (deptEmployee == null) {
                return ResponseVO.error("用户名或密码错误");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ResponseVO.success(deptEmployee);
    }

    @Override
    public ResponseVO<Admin> adminLogin(LoginDTO loginDTO) {
        Admin admin = null;
        try {
            admin = loginDAOImpl.adminLogin(loginDTO);
            if (admin == null) {
                return ResponseVO.error("用户名或密码错误");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ResponseVO.success(admin);
    }
}
